package com.itheima.service;


import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.KnowledgeBaseDao;
import com.itheima.entity.PageResult;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.FoodsInfo;
import com.itheima.pojo.SportsInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = KnowledgeBaseService.class)
@Transactional
public class KnowledgeBaseServiceImpl implements KnowledgeBaseService {

    @Autowired
    private KnowledgeBaseDao knowledgeBaseDao;

    @Override
    public PageResult pageQuery(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage,pageSize);
        Page<FoodsInfo> page = knowledgeBaseDao.selectByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void addSportInfo(List<SportsInfo> sportsInfosList) {
        for (SportsInfo sportsInfo : sportsInfosList) {
            knowledgeBaseDao.addSportInfo(sportsInfo);
        }
    }

    @Override
    public void addFoodInfo(List<FoodsInfo> foodsInfosList) {
        for (FoodsInfo foodsInfo : foodsInfosList) {
            knowledgeBaseDao.addFoodInfo(foodsInfo);
        }

    }

    @Override
    public FoodsInfo findFoodById(Integer id) {
        return knowledgeBaseDao.findFoodById(id);
    }

    @Override
    public SportsInfo selectSportById(Integer id) {
        return knowledgeBaseDao.selectSportById(id);
    }

    @Override
    public void edit(FoodsInfo foodsInfo) {
        knowledgeBaseDao.edit(foodsInfo);
    }

    @Override
    public void delete(Integer id) {
        knowledgeBaseDao.deleteById(id);
    }
    @Override
    public void deleteSport(Integer id) {
        knowledgeBaseDao.deleteSport(id);

    }

    @Override
    public void add(FoodsInfo foodsInfo) {
        knowledgeBaseDao.add(foodsInfo);
    }

    @Override
    public void addSport(SportsInfo sportsInfo) {
        knowledgeBaseDao.addSport(sportsInfo);

    }

    @Override
    public void editSport(SportsInfo sportsInfo) {
        knowledgeBaseDao.editSport(sportsInfo);
    }



    @Override
    public PageResult pageQuery1(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage,pageSize);
        Page<FoodsInfo> page = knowledgeBaseDao.selectByCondition1(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }


}
